package glassline.driver;
import glassline.ConveyorAgent;
import glassline.ConveyorAgent.PopupLocation;
import glassline.ConveyorAgent.SensorType;
import glassline.Glass;
import glassline.Glass.GlassShape;
import glassline.Glass.WorkStation;
import glassline.PopupAgent;
import glassline.SensorAgent;
import glassline.WorkstationAgent;
import glassline.mock.MockGUI;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JFrame;

import transducer.TChannel;
import transducer.TEvent;
import transducer.Transducer;

public class main extends JFrame implements KeyListener 
{
	static Transducer t = new Transducer();
	public main()
	{
		this.addKeyListener(this);
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	public static void main(String[] args)
	{
		main Main = new main();
		ConveyorAgent conveyor = new ConveyorAgent(t,1);
		ConveyorAgent prevConveyor = new ConveyorAgent(t,0);
		ConveyorAgent nextConveyor = new ConveyorAgent(t,2);
		PopupAgent popup = new PopupAgent(t, conveyor,0);
		WorkstationAgent workstation = new WorkstationAgent(popup,t,Glass.WorkStation.CrossSeamer,0);
		SensorAgent prePopupSensor = new SensorAgent(conveyor,t,0);
		SensorAgent popupSensor = new SensorAgent(conveyor,t,1);
		SensorAgent endSensor = new SensorAgent(conveyor,t,2);
		WorkStation[] works = {WorkStation.CrossSeamer};
		Glass g = new Glass(GlassShape.Circle,works);
		MockGUI gui = new MockGUI(t);
		
		popup.addWorkstation(workstation);
		conveyor.addPopup(popup, WorkStation.CrossSeamer, PopupLocation.middle);
		conveyor.addSensor(endSensor,SensorType.transit,popup,true);
		conveyor.addSensor(popupSensor,SensorType.popup, popup, false);
		conveyor.addSensor(prePopupSensor, SensorType.prePopup, popup,false);
		conveyor.introduceConveyor(prevConveyor, true);
		conveyor.introduceConveyor(nextConveyor, false);
		
		
		
		conveyor.startThread();
		popup.startThread();
		workstation.startThread();
		prePopupSensor.startThread();
		popupSensor.startThread();
		endSensor.startThread();
		
		conveyor.msgHereIsGlass(g);
		
	}
	public void keyPressed(KeyEvent e)
	{
		if(e.getKeyChar() == 'a')
		{
			Object array[] = {0};
			t.fireEvent(TChannel.SENSORS,TEvent.SENSED_GLASS,array);
		}
		if(e.getKeyChar() == 's')
		{
			Object array[] = {1};
			t.fireEvent(TChannel.SENSORS,TEvent.SENSED_GLASS,array);
		}
		if(e.getKeyChar() == 'd')
		{
			Object array[] = {2};
			t.fireEvent(TChannel.SENSORS,TEvent.SENSED_GLASS,array);
		}
	}
	@Override
	public void keyReleased(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	
}
